package com.sctvcloud.renhe.ui.widget;

import android.content.Context;
import android.media.MediaPlayer;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.renhe.R;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer;

import moe.codeest.enviews.ENDownloadView;
import tv.danmaku.ijk.media.player.IMediaPlayer;

/**
 * Created by liuyu on 2017/9/17.
 */

public class ItemPlayerView extends BasePlayerView {

    public ItemPlayerView(Context context, Boolean fullFlag) {
        super(context, fullFlag);
    }

    public ItemPlayerView(Context context) {
        super(context);
    }

    public ItemPlayerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void basePlayerInit(Context context) {
        super.basePlayerInit(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.video_layout_item;
    }

    @Override
    protected void changeUiToNormal() {
        Debuger.printfLog("changeUiToNormal");

        updateStartImage();
        setViewShowState(mTopContainer, INVISIBLE);
        setViewShowState(mBottomContainer, INVISIBLE);
        setViewShowState(mStartButton, VISIBLE);
        setViewShowState(mLoadingProgressBar, INVISIBLE);
        setViewShowState(mThumbImageViewLayout, VISIBLE);
        setViewShowState(mBottomProgressBar, INVISIBLE);
        setViewShowState(mLockScreen, (mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
        setViewShowState(progressLay, GONE);
    }

    @Override
    protected void changeUiToPreparingShow() {
        Debuger.printfLog("changeUiToPreparingShow");

        setViewShowState(mTopContainer, showTop() ? VISIBLE : INVISIBLE);
        setViewShowState(mBottomContainer, VISIBLE);
        setViewShowState(mStartButton, INVISIBLE);
        setViewShowState(mLoadingProgressBar, VISIBLE);
        setViewShowState(mThumbImageViewLayout, VISIBLE);
        setViewShowState(mBottomProgressBar, INVISIBLE);
        setViewShowState(mBackButton, GONE);
        setViewShowState(mLockScreen, GONE);
        setViewShowState(progressLay, GONE);
        setViewShowState(fullBtn, GONE);

    }

    @Override
    protected void changeUiToPlayingShow() {
        Debuger.printfLog("changeUiToPlayingShow");

        setViewShowState(mTopContainer, VISIBLE);
        setViewShowState(mBottomContainer, VISIBLE);
        setViewShowState(mStartButton, GONE);
        setViewShowState(mLoadingProgressBar, INVISIBLE);
        setViewShowState(mThumbImageViewLayout, INVISIBLE);
        setViewShowState(mBottomProgressBar, INVISIBLE);
        setViewShowState(mBackButton, GONE);
        setViewShowState(mLockScreen, (mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
        setViewShowState(progressLay, GONE);
        setViewShowState(fullBtn, GONE);
        updateStartImage();
    }

    @Override
    protected void changeUiToPlayingBufferingShow() {
        Debuger.printfLog("changeUiToPlayingBufferingShow");

        setViewShowState(mTopContainer, VISIBLE);
        setViewShowState(mBottomContainer, VISIBLE);
        setViewShowState(mStartButton, INVISIBLE);
        setViewShowState(mLoadingProgressBar, VISIBLE);
        setViewShowState(mThumbImageViewLayout, INVISIBLE);
        setViewShowState(mBottomProgressBar, INVISIBLE);
        setViewShowState(mLockScreen, GONE);
        setViewShowState(mBackButton, GONE);

    }

    @Override
    protected void changeUiToCompleteShow() {
        Debuger.printfLog("changeUiToCompleteShow");

        setViewShowState(mTopContainer, VISIBLE);
        setViewShowState(mBottomContainer, VISIBLE);
        setViewShowState(mStartButton, VISIBLE);
        setViewShowState(mLoadingProgressBar, INVISIBLE);
        setViewShowState(mThumbImageViewLayout, VISIBLE);
        setViewShowState(mBottomProgressBar, INVISIBLE);
        setViewShowState(mBackButton, GONE);
        setViewShowState(mLockScreen, (mIfCurrentIsFullscreen && mNeedLockFull) ? VISIBLE : GONE);
        updateStartImage();
    }

    @Override
    protected void changeUiToPauseShow() {
        super.changeUiToPauseShow();
    }

    @Override
    public void setThumbImageView(View view) {
        if (mThumbImageViewLayout != null) {
            mThumbImageView = view;
            resolveThumbImage(view);
        }
    }

    @Override
    public void onVideoPause() {
        super.onVideoPause();
        mCurrentPosition = 0;
    }

    public boolean isPlaying() {
        return mCurrentState == CURRENT_STATE_PLAYING;
    }

    public boolean isInPlay() {
        return mCurrentState >= CURRENT_STATE_PREPAREING && mCurrentState < CURRENT_STATE_AUTO_COMPLETE;
    }

}
